#include <gtest/gtest.h>

#include "elisa/elisa.h"
#include "elisa/parser/elisa_parser.h"

using namespace std;
using namespace elisa;

namespace {

	TEST(ElisaTest, Simple) {
		elisa::init();
		ElisaParser parser;

		ASSERT_TRUE(parser.parseString(
			"Consistency local=HC4; Variables hoge in [0.0, 100.0]; Constraints hoge^2=5;"));

		Model model(parser.model());
		elisa::IntervalSolver solver(model);

		ASSERT_TRUE(solver.next());
		ASSERT_TRUE(dynamic_cast<RealVar *>(parser.variables()["hoge"].get())->domain().
			contains(2.23606798));

		elisa::dismiss();
	}

	TEST(ElisaTest, Abc) {
		elisa::init();
		elisa::useBC3();
		ElisaParser parser;

		ASSERT_TRUE(parser.parseFile("../benchmarks/abc"));

		Model model(parser.model());
		elisa::IntervalSolver solver(model);

		ASSERT_TRUE(solver.next());
cout << "x: " << dynamic_cast<RealVar *>(parser.variables()["x"].get())->domain() << endl;
		ASSERT_TRUE(dynamic_cast<RealVar *>(parser.variables()["x"].get())->domain().
			overlaps(Interval(1.426161, 1.426162)));

		elisa::dismiss();
	}

	TEST(ElisaTest, Caprasse) {
		elisa::init();
		elisa::useBC3();
		ElisaParser parser;

		ASSERT_TRUE(parser.parseFile("../benchmarks/caprasse"));

		Model model(parser.model());
		elisa::IntervalSolver solver(model);

		ASSERT_TRUE(solver.next());
		ASSERT_TRUE(dynamic_cast<RealVar *>(parser.variables()["x"].get())->domain().
			//overlaps(Interval(-3.8637033715892759, -3.863703223052315)));
			contains(0.0));

		elisa::dismiss();
	}

	TEST(ElisaTest, Chemistry1) {
		elisa::init();
		elisa::useBC3();
		ElisaParser parser;

		ASSERT_TRUE(parser.parseFile("../benchmarks/chemistry1"));

		Model model(parser.model());
		elisa::IntervalSolver solver(model);

		ASSERT_TRUE(solver.next());
		ASSERT_TRUE(dynamic_cast<RealVar *>(parser.variables()["z1"].get())->domain().
			overlaps(Interval(124.7643488223809, 124.76434885859851)));
		ASSERT_TRUE(solver.next());
		ASSERT_TRUE(dynamic_cast<RealVar *>(parser.variables()["z1"].get())->domain().
			overlaps(Interval(131.74756440396092, 131.74756446489326)));

		elisa::dismiss();
	}

}  // namespace
